package com.mobialia.socialmediademo;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.google.ads.AdView;


public class FacebookActivity extends Activity {
	
	public final static String TAG = "FacebookActivity";
			

	public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        
		// No Titlebar
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		requestWindowFeature(Window.FEATURE_PROGRESS);
 	    
	    setContentView(R.layout.facebook);
    }
	
	@Override
	protected void onResume() {
		super.onResume();
		
    	SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    	if ("".equals(sharedPrefs.getString("facebook_id", ""))) {
    		Intent intent = new Intent(getApplicationContext(), FacebookAuthActivity.class);
    		startActivity(intent);
    		finish();
    	} else {
    		String gender = sharedPrefs.getString("facebook_gender", "");
    		String birthday = sharedPrefs.getString("facebook_birthday", ""); 
    		((TextView) findViewById(R.id.FacebookId)).setText(sharedPrefs.getString("facebook_id", ""));
    		((TextView) findViewById(R.id.FacebookName)).setText(sharedPrefs.getString("facebook_name", ""));
    		((TextView) findViewById(R.id.FacebookGender)).setText(gender);
    		((TextView) findViewById(R.id.FacebookBirthday)).setText(birthday);
    		
    	    // Look up the AdView as a resource and load a request.
    		MyAdManager.initialize(this, gender, birthday);
    	    MyAdManager.loadAd((AdView)this.findViewById(R.id.adView));
    	}
	}
	
	public void onBackAction(View v) {
		finish();
	}
	
    public void onLogoutAction(View v) {
    	SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
		SharedPreferences.Editor editor = sharedPrefs.edit();
		editor.putString("facebook_id", "");
		editor.commit();
    	finish();
    }
}